home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 April / enter-2004-04.iso / files / httrack-3.30.exe / {app} / src / webhttrack < prev   
Encoding:
Text File  |  2003-10-05  |  3.5 KB  |  102 lines

  1. #!/bin/bash
  2. #
  3. # WebHTTrack launcher script
  4. # Initializes the htsserver GUI frontend and launch the default browser
  5. BROWSEREXE=
  6. SRCHBROWSEREXE="x-www-browser www-browser mozilla galeon konqueror opera netscape"
  7. if test -n "${BROWSER}"; then
  8. # sensible-browser will f up if BROWSER is not set
  9. SRCHBROWSEREXE="sensible-browser ${SRCHBROWSEREXE}"
  10. fi
  11. SRCHPATH="/usr/local/bin /usr/share/bin /usr/bin /usr/lib/httrack /usr/local/lib/httrack /usr/local/share/httrack ${HOME}/usr/bin ${HOME}/bin"
  12. SRCHDISTPATH="/usr/share /usr/local /usr /local /usr/local/share ${HOME}/usr ${HOME}/usr/share ${HOME}/usr/local ${HOME}/usr/share"
  13.  
  14. ###
  15. # And now some famous cuisine
  16.  
  17. function log {
  18. echo "$0($$): $@" >&2
  19. return 0
  20. }
  21.  
  22. # First ensure that we can launch the server
  23. BINPATH=
  24. for i in ${SRCHPATH}; do
  25.     ! test -n "${BINPATH}" && test -x ${i}/htsserver && BINPATH=${i}
  26. done
  27. for i in ${SRCHDISTPATH}; do
  28.     ! test -n "${DISTPATH}" && test -f "${i}/httrack/lang.def" && DISTPATH="${i}/httrack"
  29. done
  30. test -n "${BINPATH}" || ! log "could not find htsserver" || exit 1
  31. test -n "${DISTPATH}" || ! log "could not find httrack directory" || exit 1
  32. test -f ${DISTPATH}/lang.def || ! log "could not find ${DISTPATH}/lang.def" || exit 1
  33. test -f ${DISTPATH}/lang.indexes || ! log "could not find ${DISTPATH}/lang.indexes" || exit 1
  34. test -d ${DISTPATH}/lang || ! log "could not find ${DISTPATH}/lang" || exit 1
  35. test -d ${DISTPATH}/html || ! log "could not find ${DISTPATH}/html" || exit 1
  36.  
  37. # Locale
  38. HTSLANG="${LC_MESSAGES}"
  39. ! test -n "${HTSLANG}" && HTSLANG="${LC_ALL}"
  40. ! test -n "${HTSLANG}" && HTSLANG="${LANG}"
  41. test -n "${HTSLANG}" && HTSLANG="`echo ${HTSLANG} | cut -c1-2` | tr 'A-Z' 'a-z'"
  42. LANGN=`grep "${HTSLANG}:" ${DISTPATH}/lang.indexes | cut -f2 -d':'`
  43. ! test -n "${LANGN}" && LANGN=1
  44.  
  45. # Find the browser
  46. # note: not all systems have sensible-browser or www-browser alternative
  47. # thefeore, we have to find a bit more if sensible-browser could not be found
  48. for i in ${SRCHBROWSEREXE}; do
  49. for j in ${SRCHPATH}; do
  50. if test -x ${j}/${i}; then
  51. BROWSEREXE=${j}/${i}
  52. fi
  53. test -n "$BROWSEREXE" && break
  54. done
  55. test -n "$BROWSEREXE" && break
  56. done
  57. test -n "$BROWSEREXE" || ! log "cound not find any suitable browser" || exit 1
  58.  
  59. # "browse" command
  60. if test "$1" = "browse"; then
  61. ${BROWSEREXE} "file://${HOME}/websites/index.html"
  62. exit $?
  63. fi
  64.  
  65. # Create a temporary filename
  66. TMPSRVFILE="/tmp/.webhttrack.$$.`/usr/bin/head -c16 /dev/random | /usr/bin/md5sum | /usr/bin/cut -f1 -d' '`"
  67. >${TMPSRVFILE} || ! log "cound not create the temporary file ${TMPSRVFILE}" || exit 1
  68. # Launch htsserver binary and setup the server
  69. (${BINPATH}/htsserver "${DISTPATH}/" path "${HOME}/websites" lang "${LANGN}" $@; echo SRVURL=error) > ${TMPSRVFILE}&
  70. # Find the generated SRVURL
  71. SRVURL=
  72. MAXCOUNT=60
  73. while ! test -n "$SRVURL"; do
  74. MAXCOUNT=$[$MAXCOUNT - 1]
  75. test $MAXCOUNT -gt 0 || exit 1
  76. test $MAXCOUNT -lt 50 && echo "waiting for server to reply.."
  77. SRVURL=`/bin/grep -E URL= ${TMPSRVFILE} | /usr/bin/cut -f2- -d=`
  78. test ! "$SRVURL" = "error" || ! log "could not spawn htsserver" || exit 1
  79. test -n "$SRVURL" || /bin/sleep 1
  80. done
  81.  
  82. # Cleanup function
  83. function cleanup {
  84. test -n "$1" && log "nasty signal caught, cleaning up.."
  85. test -f ${TMPSRVFILE} && SRVPID=`/bin/grep -E PID= ${TMPSRVFILE} | /usr/bin/cut -f2- -d=`
  86. test -n "${SRVPID}" && kill -9 ${SRVPID}
  87. test -f ${TMPSRVFILE} && rm ${TMPSRVFILE}
  88. test -n "$1" && log "..done"
  89. return 0
  90. }
  91.  
  92. # Cleanup in case of emergency
  93. trap "cleanup now; exit" 1 2 3 4 5 6 7 8 9 11 13 14 15 16 19 24 25
  94.  
  95. # Got SRVURL, launch browser
  96. ${BROWSEREXE} "${SRVURL}"
  97.  
  98. # That's all, folks!
  99. trap "" 1 2 3 4 5 6 7 8 9 11 13 14 15 16 19 24 25
  100. cleanup
  101. exit 0
  102.